<template>
  <el-row>
    <el-row class="search-bar">
      <el-col :span="5">
        <el-input placeholder="请输入内容" width="100px" v-model="searchInput" clearable></el-input>
      </el-col>
      <el-col :span="5">
        <el-button type="primary" icon="el-icon-search" @click="handleSearch">搜索</el-button>
      </el-col>
    </el-row>
    <el-row>
      <el-table v-loading="loading" :data="tableData" border style="width: 100%">
        <el-table-column prop="id" label="序号" width="200"></el-table-column>
        <el-table-column prop="username" label="用户名" width="150"></el-table-column>
        <el-table-column prop="host" label="主机" width="200"></el-table-column>
        <el-table-column prop="loginTime" label="登录时间" width="270"></el-table-column>
        <el-table-column prop="lastLoginTime" label="最后访问时间" width="270"></el-table-column>
        <el-table-column prop="expire" label="过期时间" width="150"></el-table-column>
        <el-table-column prop="status" label="状态" width="100">
          <template slot-scope>
            <el-tag disable-transitions>在线</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="100">
          <template slot-scope="scope">
            <el-button @click="handleClick(scope.$index)" type="danger">X</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-row>
    <el-row>
      <el-pagination background layout="prev, pager, next" :total="1000"></el-pagination>
    </el-row>
  </el-row>
</template>

<script>
import * as request from "@net";

export default {
  methods: {
    handleSearch(){
      var _this = this;
      _this.loading = true;
      request.findOnlineUsersByName(this.searchInput,function ({data}) {
        _this.tableData = data;
        _this.loading = false;
      })
    },
    handleClick() {
      alert("执行成功");
    }
  },
  data() {
    return {
      loading: true,
      tableData: [
        // {
        //   id: "3640bd5e-bfac-4ea4-a0f6-0dbb06f58bee",
        //   username: "SUDDEV",
        //   host: "106.119.63.2041",
        //   loginTime: "2019-05-07 23:58:21",
        //   lastLoginTime: "2019-05-07 23:58:56",
        //   expire: "1800000",
        //   status: 1
        // },
        // {
        //   id: "dd4cc271-7e30-4f27-ab51-e26f137602e8",
        //   username: "Admin",
        //   host: "123.118.124.71",
        //   loginTime: "2019-05-07 23:35:35",
        //   lastLoginTime: "2019-05-07 23:36:45",
        //   expire: "1800000",
        //   status: 1
        // }
      ],
      searchInput: ''
    };
  },
  created(){
    var _this = this;
    request.getUsers(function ({data}) {
      _this.tableData = data;
      _this.loading = false;
    });
  }
};
</script>

<style scoped>
.el-row {
  margin-left: 10px;
}
.el-pagination {
  text-align: center;
}
.search-bar {
  margin-top: 10px;
}
</style>

